<template>
    <h2>查看（待审批）</h2>
    <el-form ref="ruleFormRef" style="max-width: 600px" :model="from" :rules="rules" label-width="auto"
        class="demo-ruleForm" :size="formSize" status-icon>

        <el-form-item label="标题" prop="headline">
            <el-input v-model="from.headline" placeholder="请输标题" />
        </el-form-item>
        <el-form-item label="用途描述" prop="purposeDescription">
            <el-input v-model="from.purposeDescription" type="textarea" placeholder="请输入用途描述" />
        </el-form-item>
        <el-form-item label="备注" prop="sPReserveNote">
            <el-input v-model="from.sPReserveNote" type="textarea" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="选择领用物品" prop="headline">
        </el-form-item>


        <table v-if="selectI.length > 0" border>
            <thead>
                <tr>
                    <th>货物名称</th>
                    <th>类型</th>
                    <th>材质</th>
                    <th>规格</th>
                    <th>产地</th>
                    <th>仓库数量</th>
                    <th>领用数量</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="(inde, index) in selectI">
                    <td>{{ inde.sMCargoName }}</td>
                    <td> {{ inde.typeName }}</td>
                    <td> {{ inde.materiaLqualityName }}</td>
                    <td> {{ inde.sMGaugeLattice }}</td>
                    <td> {{ inde.nationName }}-{{ inde.provinceName }}</td>
                    <td> {{ inde.sMQuantity }}</td>
                    <td>
                        <el-input v-model="numberArray[index]" style="width: 90px;" />
                    </td>
                </tr>
            </tbody>
        </table>
        <el-form-item label="审批备注" prop="remarks">
            <el-input v-model="ruleForm.remarks"  />
        </el-form-item>
        <el-form-item label="转批人">
            <el-select v-model="ruleForm.superstratumCharge" placeholder="请选择转批人">
                <el-option v-for="item in tableUser" :label="item.name" :value="item.name" />
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="Pass(xid = 1)">通过并转批</el-button>
            <el-button @click="Pass(xid = 2)">拒绝</el-button>
            <el-button type="primary" @click="Pass(xid = 3)"> 通过并终止转批</el-button>
        </el-form-item>
    </el-form>
</template>

<script setup lang='ts'>
import { reactive, ref, onMounted, watch } from 'vue'
import type { ComponentSize, FormInstance, FormRules } from 'element-plus'
import { ElMessage, ElMessageBox } from 'element-plus'
import axios from 'axios';
const formSize = ref<ComponentSize>('default')
const ruleFormRef = ref<FormInstance>()
import { useRouter, useRoute } from 'vue-router'
const router = useRouter()
const route = useRoute()

//数据信息
const from = reactive({

    "receivingID": 0,
    "headline": "",
    "purposeDescription": "",
    "sPReserveNote": "",
    "sPFirmId": "",
    "sPUserId": 0,
    "sPApprover": "",
    "sPApprovalStatus": 1,
    "createName": "",
    "createDate": "",
    "updateName": "李四",
    "selectItemsToReceiveDTOList": []
})
const tiaojian = ref("")
const selectI = ref([])
const numberArray = ref([])
const selectItemsToReceiveID = ref([])
onMounted(() => {
    ALLStockManagementList()
    FTReceivingInfo()
    GetUser()
})
//反填route.query.id

const FTReceivingInfo = () => {
    axios.get("http://10.223.8.2:8000/ReadMaterial/api/Receiving/ReceivingInfo?receivingID=" + route.query.id).then(res => {
        console.log(res.data.data)
        from.receivingID = res.data.data[0].receivingID
        from.headline = res.data.data[0].headline
        from.purposeDescription = res.data.data[0].purposeDescription
        from.sPReserveNote = res.data.data[0].sPReserveNote
        from.sPFirmId = res.data.data[0].sPFirmId
        from.sPUserId = res.data.data[0].sPUserId
        from.sPApprover = res.data.data[0].sPApprover
        from.sPApprovalStatus = res.data.data[0].sPApprovalStatus
        from.createName = res.data.data[0].createName
        from.createDate = res.data.data[0].createDate
        for (let index = 0; index < res.data.data[0].selectItemsToReceiveDTOList.length; index++) {
            let sMCargoID = res.data.data[0].selectItemsToReceiveDTOList[index].sMCargoID
            numberArray.value.push(res.data.data[0].selectItemsToReceiveDTOList[index].sIPQuantity)
            selectItemsToReceiveID.value.push(res.data.data[0].selectItemsToReceiveDTOList[index].selectItemsToReceiveID)
            axios.get("http://10.223.8.2:8000/ReadMaterial/api/Receiving/RStockManagementList?sMCargoID=" + sMCargoID).then(res => {
                //selectI.value = res.data.data
                selectI.value.push(res.data.data[0])//[{}, {}, {}]
                console.log(selectI.value)
            }).catch(err => {
                console.log(err)
            })

        }
        console.log(from)
    }).catch(err => {
        console.log(err)
    })
}



//显示列表选择
const ALLStockManagement = ref([])
const ALLStockManagementList = () => {
    axios.get("http://10.223.8.2:8000/ReadMaterial/api/Receiving/ALLStockManagementList").then(res => {
        ALLStockManagement.value = res.data.data
        console.log(ALLStockManagement.value)
    }).catch(err => {
        console.log(err)
    })
}
const ruleForm=reactive({
    name: route.query.name,
    remarks: "",
    personnelId: route.query.id,
    field: 0,
    tableName:"物资领用"
})
const tableUser = ref([]);
const GetUser = () => {
    axios({
        method: "get",
        url: "http://47.96.109.219:5202/api/User/UserSelectShow"
    })
        .then(res => {
            tableUser.value = res.data.data
        })
}
let xid=0;
const Pass = (id: number) => {
    axios.post("http://10.223.8.2:8000/Material/api/MateralApproval/Updateling", {
        name: route.query.name,
        remarks: ruleForm.remarks,
        personnelId: route.query.id,
        field: id,
        tableName:ruleForm.tableName
    })
        .then(res => {
            if (res.data.data > 0) {
                router.push({
                    name: "PurchasingApproval"
                })
            }
            else {

            }
        })
}
</script>

<style></style>